import axios  from 'axios'
import { getToken,clearToken } from '@/utils/localStorage.js'
const service = axios.create({
    baseURL: 'http://localhost:8008', // api的base_url
    timeout: 500000 // 请求超时时间
  })
  service.interceptors.request.use(config => {
    // 不是login添加token
    if (config.url!="/") {
      config.headers["token"] = getToken();
    }
    return config
  }, error => {
    return Promise.reject(error);
  })
  
  // respone拦截器
  service.interceptors.response.use(
    response => {
      // console.log(response);
      if (response.data.code === "5555") {
        clearToken();
        window.location.href = "/";
      }
      return response;
    }, error => {
      console.log("error");
      console.log(error);
      return Promise.reject(error)
    })
  
  export default service